﻿using System.ComponentModel;
using System.IO.Pipes;

namespace reaction_game
{
    internal class Program
    {
        /// <summary>
        /// reaction game
        /// </summary>
        /// <param name="args"></param>
        enum Direction
        {
            up,
            down,
            left,
            right
        }
        static void Main(string[] args)
        {
            Random random = new Random();
            const int Totaltimes = 10;
            TimeSpan time;
            int WrongTime = 0;
            //记录开始时间
            DateTime start = DateTime.Now;
            for (int i = 1; i<=Totaltimes; i++)
            {
                Console.Clear();
                //记录总用时
                time = DateTime.Now-start;
                Console.WriteLine($"第{i}次试验，总用时{time.TotalSeconds},已错{WrongTime}次");
                //输出方向
                Direction direction = (Direction)random.Next(0, 4);
                Console.WriteLine(direction.ToString());
                //判断输入正误
                bool ans = false;
                do
                {
                    var key = Console.ReadKey();
                    switch (direction)
                    {
                        case Direction.up:
                            if (key.Key == ConsoleKey.UpArrow) ans=true;
                            break;
                        case Direction.down:
                            if (key.Key == ConsoleKey.DownArrow) ans=true;
                            break;
                        case Direction.left:
                            if (key.Key == ConsoleKey.LeftArrow) ans=true;
                            break;
                        case Direction.right:
                            if (key.Key == ConsoleKey.RightArrow) ans=true;
                            break;
                        default:
                            ans=false;
                            break;
                    }
                    //记录错误次数
                    if (ans==false) WrongTime++;
                } while (ans==false);

            }

        }
    }
}
